package com.wd.servlet;

import com.wd.entity.Blog;
import com.wd.entity.User;
import com.wd.service.BlogService;
import com.wd.service.impl.BlogServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @Author: 悠久的苍穹
 * @Date: 2020/11/7 23:55
 * @Description: ${description}
 * @Version: 1.0
 */
@WebServlet(urlPatterns = "/LikeShowServlet")
public class LikeShowServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            response.setContentType("text/html;charset=UTF-8");
            request.setCharacterEncoding("UTF-8");
            User user = (User) request.getSession().getAttribute("user");
//            String author = request.getParameter("author");
            BlogService blogService = new BlogServiceImpl();
            List<Blog> blogs = blogService.selLikeBlog(user.getAccount());
            request.setAttribute("blogs",blogs);
            request.getRequestDispatcher("/blog/like.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TagServlet.isIllegalLogin(request,response);
        HttpSession session=request.getSession();
        String placeLogin =(String) session.getAttribute("illegalLogin");
        if(placeLogin.equals("请登录")){
            return;
        }
        doGet(request, response);
    }
}
